package com.clickpaas.materialsprocurement.service.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.SupplierInformationDTO;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.SupplierInformationDTOPageInfoResponse;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.SupplierInformationDTOResponse;
import com.clickpaas.materialsprocurement.dao.SupplierInformationDao;
import com.clickpaas.materialsprocurement.entity.SupplierInformationEntity;
import com.clickpaas.materialsprocurement.service.SupplierInfoService;
import com.clickpaas.materialsprocurement.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SupplierInfoServiceImpl implements SupplierInfoService {
    @Resource
    private SupplierInformationDao supplierInformationDao;
    /**
     * 获取供应商资料数据
     * @return
     */
    public List<SupplierInformationDTO> getSupplierInfoInfo(SupplierInformationEntity supplierInformationEntity) {

        List<SupplierInformationDTO> reList;
        try {
            /**
             * 入参为空,查询全部数据
             */
            if (null == supplierInformationEntity || DataInfoUtil.isAllFieldNull(supplierInformationEntity)){
                reList = DataInfoUtil.castListCopy(supplierInformationDao.getSupplierInfoByCondtion(), SupplierInformationDTOPageInfoResponse.class,SupplierInformationDTO.class);
            }else {
                reList = DataInfoUtil.castListCopy(supplierInformationDao.getSupplierInfoByCondtion(supplierInformationEntity), SupplierInformationDTOResponse.class,SupplierInformationDTO.class);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",supplierInformationEntity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 供应商资料数据转换为bean
     * @return
     */
    public List<SupplierInformationEntity> supplierInfoDataConver(List<SupplierInformationDTO> list) {
        return DataInfoUtil.castListCopy(list,SupplierInformationDTO.class,SupplierInformationEntity.class);
    }
}
